Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement codefix to make positional DUs used named syntax #895

Merged
merged 2 commits into from
Mar 13, 2022

Conversation

baronfel
Copy link
Contributor

@baronfel baronfel commented Mar 13, 2022

This adds a codefix to convert 'positional' DU bindings and match patterns to 'named' DU versions.

Example:

type Person = Person of first: string * middle: string option * last: string

let (Person(f, m, l)) = person
// becomes
let (Person(first = f; middle = m; last = l)) = person

It also works with scenarios where a DU has been updated with more fields than a positional pattern accounts for:

type B = B of a: char * b: bool

let b = B(' ', true)

match b with
| B('a') -> ()

// becomes

match b with
| B(a = 'a', b = _;) -> ()

In each case, the entire range of the pattern of the positional binding is used as the right-hand side of the matching named pattern.

Tests added!

@baronfel baronfel force-pushed the codefix-du-match-positional-to-named branch from 48398b6 to 509c915 Compare March 13, 2022 21:04
@baronfel baronfel marked this pull request as ready for review March 13, 2022 22:16
@baronfel baronfel merged commit f8a19df into ionide:main Mar 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant